<template>
  <view class="editor-page">
		<cu-custom bgColor="bgmain" :isBack="true">
			<view slot="content">店员信息</view>
		</cu-custom>
		<view class="box margin padding">
			<uni-forms :modelValue="formData" label-position="top" label-width="300">
				<uni-forms-item label="用户id" name="name">
					<uni-easyinput type="number" v-model="formData.u_id" :disabled="id"
					placeholder="请输入用户id" :primaryColor="style.color" />
				</uni-forms-item>
				<uni-forms-item label="姓名" name="name">
					<uni-easyinput  v-model="formData.name" :disabled="formData.is_many == 0"
					placeholder="请输入这恩施姓名" :primaryColor="style.color" />
				</uni-forms-item>
				<uni-forms-item label="头像" name="name">
					<view class="avatar row" @click="choose">
						<image
							class="avatar"
							:src="formData.avatar"
							mode="scaleToFill"
							v-if="formData.avatar"
						/>
						<view class="cuIcon-camera" v-else></view>
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>
		<view class="submit" :style="{
			background: style.color
		}" @click="submit">提交</view>

	</view>
</template>

<script>
import Vue from 'vue';
import siteInfo from '@/siteinfo.js';

export default Vue.extend({
  components: {},
  data() {
    return {
      	formData: {
			u_id:"",
			name:"",
			avatar:""
      	},
		style: {
			color: "#ff6344"
		},
		id:"",
		query:{},
		item:{}
    }
  },
  computed: {},
  methods: {
	submit(){
		this.request(this.id?'ZhBusinesss/film_edit':"ZhBusinesss/film_add",{
			...this.formData,
			...this.query

		}).then(res=>{
			console.log(res);
			if (res.data.status==200) {
				this.tips.success(res.data.msg).then(res=>{
					uni.navigateBack({ delta: 1 })
				})
			}
		})
	},
		choose() {
			var self = this
			uni.chooseImage({
				count: 1,
				sizeType: ['original', 'compressed'],
				sourceType: ['album'],
				success: (res) => {
					console.log('path', res);
					uni.showLoading({
						title: '上传中...',
						mask: true
					});
					uni.uploadFile({
						url: siteInfo.url + 'Base/upload',
						filePath: res.tempFilePaths[0],
						formData: {
							'wxapp_id': siteInfo.uniacid
						},
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						name: 'file',
						success: (result) => {
							var data = JSON.parse(result.data);
							if (data.status == 200) {
								self.formData.avatar = data.data;
								uni.hideLoading();
							} else {
								uni.showToast({
									title: data.msg,
									icon: 'none'
								})
							}
						}
					});
				}
			});
		},






  },
  watch: {},

  // 页面周期函数--监听页面加载
  onLoad(options) { 
	this.id=options.id
	if (options.id) {
		this.request('ZhBusinesss/film_view' , {
			...options
		}).then(res=>{
			this.formData =res.data.data
		})
	}
	this.query=options
  },
  // 页面周期函数--监听页面初次渲染完成
  onReady() { },
  // 页面周期函数--监听页面显示(not-nvue)
  onShow() { },
  // 页面周期函数--监听页面隐藏
  onHide() { },
  // 页面周期函数--监听页面卸载
  onUnload() { },
  // 页面处理函数--监听用户下拉动作
  // onPullDownRefresh() { uni.stopPullDownRefresh(); },
  // 页面处理函数--监听用户上拉触底
  // onReachBottom() {},
  // 页面处理函数--监听页面滚动(not-nvue)
  // onPageScroll(event) {},
  // 页面处理函数--用户点击右上角分享
  // onShareAppMessage(options) {},
}) 
</script>

<style scoped lang="scss">@import "./main.scss";</style>